home *** CD-ROM | disk | FTP | other *** search
/ One Click 11 / OneClick11.iso / Bancos de Dados / Conversao / Mysql2Excel / Setup.exe / Mysql2Excel.exe / MySQLdb / sets.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2003-06-23  |  6.0 KB  |  172 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.2)
  3.  
  4. '''sets module
  5.  
  6. This module provides some Set classes for dealing with MySQL data.
  7. '''
  8.  
  9. class Set:
  10.     '''A simple class for handling sets. Sets are immutable in the same
  11.     way numbers are.'''
  12.     
  13.     def __init__(self, *values):
  14.         '''Use values to initialize the Set.'''
  15.         self._values = values
  16.  
  17.     
  18.     def __contains__(self, value):
  19.         if not value in self._values and 1:
  20.             pass
  21.         return 0
  22.  
  23.     
  24.     def __str__(self):
  25.         '''Returns the values as a comma-separated string.'''
  26.         join = join
  27.         import string
  28.         return join(map(str, self._values), ',')
  29.  
  30.     
  31.     def __repr__(self):
  32.         return '%s%s' % (self.__class__.__name__, `self._values`)
  33.  
  34.     
  35.     def __or__(self, other):
  36.         '''Union.'''
  37.         values = list(self._values)
  38.         if isinstance(other, Set):
  39.             for v in other._values:
  40.                 if v not in values:
  41.                     values.append(v)
  42.                 
  43.             
  44.         elif other not in self._values:
  45.             values.append(other)
  46.         
  47.         return apply(self.__class__, values)
  48.  
  49.     __add__ = __or__
  50.     
  51.     def __sub__(self, other):
  52.         values = list(self._values)
  53.         if isinstance(other, Set):
  54.             for v in other._values:
  55.                 if v in values:
  56.                     values.remove(v)
  57.                 
  58.             
  59.         elif other in self:
  60.             values.remove(other)
  61.         
  62.         return apply(self.__class__, tuple(values))
  63.  
  64.     
  65.     def __and__(self, other):
  66.         '''Intersection.'''
  67.         values = []
  68.         if isinstance(other, Set):
  69.             for v in self._values:
  70.                 if v in other:
  71.                     values.append(v)
  72.                 
  73.             
  74.         elif other in self:
  75.             values.append(other)
  76.         
  77.         return apply(self.__class__, tuple(values))
  78.  
  79.     __mul__ = __and__
  80.     
  81.     def __xor__(self, other):
  82.         """Intersection's complement."""
  83.         return (self | other) - (self & other)
  84.  
  85.     
  86.     def __getitem__(self, n):
  87.         return self._values[n]
  88.  
  89.     
  90.     def __getslice__(self, n1, n2):
  91.         return self._values[n1:n2]
  92.  
  93.     
  94.     def __len__(self):
  95.         return len(self._values)
  96.  
  97.     
  98.     def __hash__(self):
  99.         return hash(self._values)
  100.  
  101.     
  102.     def __cmp__(self, other):
  103.         if isinstance(other, Set):
  104.             if not (self ^ other):
  105.                 return 0
  106.             elif self & other == self:
  107.                 return 1
  108.             else:
  109.                 return -1
  110.         elif other in self._values:
  111.             return 0
  112.         elif other > self._values:
  113.             return 1
  114.         else:
  115.             return -1
  116.  
  117.     
  118.     def __ne__(self, other):
  119.         return self ^ other
  120.  
  121.     
  122.     def __eq__(self, other):
  123.         if not (self != other):
  124.             return self
  125.         else:
  126.             return self.__class__()
  127.  
  128.     
  129.     def __le__(self, other):
  130.         return self & other == self
  131.  
  132.     
  133.     def __lt__(self, other):
  134.         if self <= other and self ^ other:
  135.             return self
  136.         else:
  137.             return self.__class__()
  138.  
  139.     
  140.     def __ge__(self, other):
  141.         return self & other == other
  142.  
  143.     
  144.     def __gt__(self, other):
  145.         if self >= other and self ^ other:
  146.             return self
  147.         else:
  148.             return self.__class__()
  149.  
  150.  
  151.  
  152. class DBAPISet(Set):
  153.     '''A special type of set for which A == x is true if A is a
  154.     DBAPISet and x is a member of that set.'''
  155.     
  156.     def __ne__(self, other):
  157.         if isinstance(other, Set):
  158.             return self % other
  159.         elif other in self._values:
  160.             return 0
  161.         else:
  162.             return 1
  163.  
  164.     
  165.     def __eq__(self, other):
  166.         if self != other:
  167.             return self.__class__()
  168.         else:
  169.             return self
  170.  
  171.  
  172.